package com.mo.axion.support.mq.kafka;

import cn.hutool.core.text.CharSequenceUtil;
import com.mo.axion.support.mq.SendMqService;
import com.mo.axion.support.mq.constants.MessageQueuePipeline;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.kafka.core.KafkaTemplate;
import org.springframework.stereotype.Service;

/**
 * @author Mo
 * @createTime 2024/2/7 15:06
 * @description Kafka发送实现类
 */
@Slf4j
@Service
@ConditionalOnProperty(name = "axion.mq.pipeline", havingValue = MessageQueuePipeline.KAFKA)
public class KafkaSendMqServiceImpl implements SendMqService {

    @Autowired
    private KafkaTemplate kafkaTemplate;

    /**
     * @param topic
     * @param jsonValue
     * @param tageId
     */
    @Override
    public void send(String topic, String jsonValue, String tageId) {
//        if (CharSequenceUtil.isNotBlank(tageId)) {
//
//        }
        kafkaTemplate.send(topic, jsonValue);
        log.info("消息送入队列中 topic:{}, value:{}", topic, jsonValue);
    }

    /**
     * @param topic
     * @param jsonValue
     */
    @Override
    public void send(String topic, String jsonValue) {
        send(topic, jsonValue, null);
    }
}
